package libra.controller;

import java.util.HashMap;
import java.util.Map;

/**
 * 响应构建器
 * @author libra
 */
public class BuildResp {
	public static String provider;
	// 构造响应返回
	public static final Map<String, String> createResp( String info ){
		Map<String, String> map = new HashMap<>();
		map.put("provider", provider);
		map.put("result", info);
		return map;
	}
	// 构造“流控”Block响应返回
	public static final Map<String, String> createBlockResp( String from ){
		Map<String, String> map = new HashMap<>();
		map.put("provider", provider);
		map.put("status", "流控_block");
		map.put("from", from);
		return map;
	}
	// 构造“流控”Fallback响应返回
	public static final Map<String, String> createFallbackResp( String from ){
		Map<String, String> map = new HashMap<>();
		map.put("provider", provider);
		map.put("status", "执行异常_fallback");
		map.put("from", from);
		return map;
	}
	// 构造“熔断”Degrade响应返回
	public static final Map<String, String> createDegradeResp( String from, Throwable throwable ){
		Map<String, String> map = new HashMap<>();
		map.put("provider", provider);
		map.put("status", "降级&熔断_degrade");
		map.put("ex_type", throwable.getClass().getSimpleName() );
		map.put("from", from );
		return map;
	}
}
